package com.oamicnet;

import com.oamicnet.entity.Student;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args ) throws ClassNotFoundException, InstantiationException, IllegalAccessException, NoSuchFieldException, NoSuchMethodException, InvocationTargetException {

        //可以拿到class
        Class<Student> studentClass = Student.class;

        Student student = Student.builder().id(1).build();
        Class<? extends Student> aClass1 = student.getClass();

        Class<?> aClass = Class.forName("com.oamicnet.entity.Student");


        //创建对象
        Constructor<?> constructor = aClass.getConstructor();
        Student student1 = (Student) constructor.newInstance();
        student1.setId(1);
        student1.setName("zhangsan1");
        student1.setEmail("zhangsan1@gmail.com");

        //调用方法
//        student1.print();
        Method method = studentClass.getMethod("print", null);
        method.invoke(student1); // 调用user对象的setName方法




    }
}
